//
//  CTQGSecondCell.m
//  digitalCurrency
//
//  Created by 默认账户 on 2019/6/2.
//  Copyright © 2019 XinHuoKeJi. All rights reserved.
//

#import "CTQGSecondCell.h"

@interface CTQGSecondCell ()
@property (nonatomic, strong) UIView *bgView;



@property (nonatomic, strong) UIImageView *rightImgView;
@end


@implementation CTQGSecondCell

+ (instancetype)createTableView:(UITableView *)tableView {
    CTQGSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:@"qgsecondcell"];
    if (!cell) {
        cell = [[CTQGSecondCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"qgsecondcell"];
        
        cell.selectionStyle  = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor blackColor];
        
        [cell makeViews];
    }
    
    return cell;
}
    
- (void)makeViews {
    [self.contentView addSubview:self.bgView];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(15);
        make.right.mas_equalTo(-12);
        make.bottom.mas_equalTo(-15);
    }];
    
    [self.bgView addSubview:self.titleImgView];
    [self.titleImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(12);
        make.width.height.mas_equalTo(44);
    }];
    
    [self.bgView addSubview:self.coinName];
    [self.coinName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(68);
        make.top.mas_equalTo(27);
        make.height.mas_equalTo(18);
    }];
    
    __weak typeof(self)weakself = self;
    
    [self.bgView addSubview:self.rightImgView];
    [self.rightImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.top.mas_equalTo(17);
        make.height.mas_equalTo(80);
        make.width.mas_equalTo(56);
    }];
    
    [self.bgView addSubview:self.canUsedCoin];
    [self.canUsedCoin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(weakself.rightImgView.mas_left).mas_offset(-25);
        make.top.mas_equalTo(16);
        make.height.mas_equalTo(13);
    }];
    
    [self.bgView addSubview:self.frozenCoin];
    [self.frozenCoin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(weakself.rightImgView.mas_left).mas_offset(-25);
        make.top.mas_equalTo(40);
        make.height.mas_equalTo(13);
    }];
    
    
    CGFloat width2_1 = (SCREEN_WIDTH-24-80)/2.0;
    
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = [UIColor colorWithHEX:@"282f3a"];
    [self.bgView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(66);
        make.width.mas_equalTo(width2_1*2.0);
        make.height.mas_equalTo(1);
    }];
    
    
    UIView *lineright = [[UIView alloc] init];
    lineright.backgroundColor = [UIColor colorWithHEX:@"282f3a"];
    [self.bgView addSubview:lineright];
    [lineright mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(line.mas_right);
        make.width.mas_equalTo(1);
        make.bottom.mas_equalTo(0);
    }];
    
    [self.bgView addSubview:self.rechargeBtn];
    [self.rechargeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(65);
        make.width.mas_equalTo(width2_1);
        make.height.mas_equalTo(43);
    }];
    
    UIView *linemid = [[UIView alloc] init];
    linemid.backgroundColor = [UIColor colorWithHEX:@"282f3a"];
    [self.bgView addSubview:linemid];
    [linemid mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(65);
        make.left.mas_equalTo(self.rechargeBtn.mas_right);
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(43);
    }];
    
    [self.bgView addSubview:self.redrawBtn];
    [self.redrawBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(width2_1);
        make.top.mas_equalTo(65);
        make.width.mas_equalTo(width2_1);
        make.height.mas_equalTo(43);
    }];

}
    
- (void)redrawClick {
    kPreventRepeatClickTime(1);
    if (self.redrawBlock) {
        self.redrawBlock();
    }
}
    
- (void)rechargeClick {
    kPreventRepeatClickTime(1);
    if (self.rechargeBlock) {
        self.rechargeBlock();
    }
}
    
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [[UIColor colorWithHEX:mainBlackColor] colorWithAlphaComponent:0.68];
    }
    return _bgView;
}
    
- (UIImageView *)titleImgView {
    if (!_titleImgView) {
        _titleImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"announce"]];
    }
    
    return _titleImgView;
}
    
- (UILabel *)coinName {
    if (!_coinName) {
        UILabel *label = [[UILabel alloc] init];
        label.textColor = [UIColor whiteColor];
        label.font = [UIFont systemFontOfSize:18];
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"DWTT" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Medium" size: 18],NSForegroundColorAttributeName: [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]}];
        label.attributedText = string;
        _coinName = label;
    }
    
    return _coinName;
}
    
- (UILabel *)canUsedCoin {
    if (!_canUsedCoin) {
        UILabel *label = [[UILabel alloc] init];
        label.textColor = [UIColor whiteColor];
        label.textAlignment = NSTextAlignmentRight;
        label.font = [UIFont systemFontOfSize:14];
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:LocalizationKey(@"可用:0.00") attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size: 14],NSForegroundColorAttributeName: [UIColor colorWithRed:246/255.0 green:246/255.0 blue:246/255.0 alpha:1.0]}];
        label.attributedText = string;
        _canUsedCoin = label;
    }
    
    return _canUsedCoin;
}
    
- (UILabel *)frozenCoin {
    if (!_frozenCoin) {
        UILabel *label = [[UILabel alloc] init];
        label.textColor = [UIColor whiteColor];
        label.textAlignment = NSTextAlignmentRight;
        label.font = [UIFont systemFontOfSize:14];
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:LocalizationKey(@"冻结:0.00") attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size: 14],NSForegroundColorAttributeName: [UIColor colorWithRed:247/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]}];
        
        label.attributedText = string;
        _frozenCoin = label;
    }
    
    return _frozenCoin;
}
    
- (UIImageView *)rightImgView {
    if (!_rightImgView) {
        _rightImgView = [[UIImageView alloc] init];
        _rightImgView.image = [UIImage imageNamed:@"qb_ct"];
    }
    
    return _rightImgView;
}
    
- (UIButton *)rechargeBtn {
    if (!_rechargeBtn) {
        _rechargeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [_rechargeBtn setTitle:LocalizationKey(@"Recharge") forState:UIControlStateNormal];
        [_rechargeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _rechargeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_rechargeBtn addTarget:self action:@selector(rechargeClick) forControlEvents:UIControlEventAllEvents];

    }
    
    return _rechargeBtn;
}
    
- (UIButton *)redrawBtn {
    if (!_redrawBtn) {
        _redrawBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_redrawBtn setTitle:LocalizationKey(@"Withdraw") forState:UIControlStateNormal];
        [_redrawBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _redrawBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_redrawBtn addTarget:self action:@selector(redrawClick) forControlEvents:UIControlEventAllEvents];
    }
    return _redrawBtn;
}
    
    
@end
